package com.ckerchina.admin.ckadmin.controller.console;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ckerchina.admin.ckadmin.controller.dto.MgrResponseData;
import com.ckerchina.admin.ckadmin.dao.AgentUserDao;
import com.ckerchina.admin.ckadmin.dao.MaterialDao;
import com.ckerchina.admin.ckadmin.dao.TeacherInfoDao;
import com.ckerchina.admin.ckadmin.domain.AgentUser;
import com.ckerchina.admin.ckadmin.domain.Material;
import com.ckerchina.admin.ckadmin.domain.MaterialOrder;
import com.ckerchina.admin.ckadmin.domain.TeacherInfo;
import com.ckerchina.admin.ckadmin.service.UpdateService;
import com.ckerchina.admin.ckadmin.utils.Page;


@Controller
public class MaterialController extends AbstractConsoleController{

	@Autowired
	private MaterialDao materialDao;
	
	@RequestMapping("material/list")	
	public @ResponseBody Page<Material> list(String material_name, int start, int limit){
		String where = "";
		Map<String, Object> params = new HashMap<String, Object>();
		if(!"".equals(material_name)){
			where += " and material_name = :material_name";
			params.put("material_name", material_name);
		}
		return materialDao.findPage(where, params, start, limit, " order by id desc");
	}
	
	@Autowired
	UpdateService updateService;
	@RequestMapping("material/add")
	public @ResponseBody MgrResponseData add(Material finfo){	 
		updateService.addMaterial(finfo);

		return new MgrResponseData("新增成功");
	}
	
	@RequestMapping("material/update")
	public @ResponseBody MgrResponseData update(TeacherInfo finfo){
		updateService.updateTeacherInfo(finfo);
		return new MgrResponseData("修改成功");
	}
	
	@RequestMapping("material/addbuy")
	public @ResponseBody MgrResponseData addbuy(MaterialOrder finfo){
//		updateService.updateTeacherInfo(finfo);
		updateService.addMaterailOrder(finfo);
		return new MgrResponseData("新增申请物料成功");
	}
}
